 

//全局变量
var giftId,activeId;
ajax({
	url:"http://www.antmall.cc/public/wx/collect/data/"+activeId+".html",
	success:function(data){
		var info = JSON.parse(data);
		console.log(info);
		var gifts=info.data.gifts;
		var oImg=document.getElementsByClassName("img")[0];
		var title=document.getElementsByClassName("title")[0];
		var total_num=document.getElementsByClassName("totalNum")[0];
		var address=document.getElementsByClassName("address")[0];
		var xs_center=document.getElementsByClassName("xs_center")[0];

		for(let i=0;i<gifts.length;i++){
			if(gifts[i].id==giftId){
				oImg.style.backgroundImage = "url("+gifts[i].giftImg+")";
				title.innerHTML=gifts[i].giftTitle;
				total_num.innerHTML=gifts[i].totalNum;
				xs_center.innerHTML=gifts[i].samples;

				var goodsinfo_button=document.getElementsByClassName("goodsinfo_button")[0];
				goodsinfo_button.onclick=function(){
					var info_cover=document.getElementsByClassName("info_cover")[0];
					info_cover.style.display = "block";
					var info_button=document.getElementById("info_button");

					info_button.onclick=function(){
						var userName=document.getElementsByClassName("username")[0].value;
						var userPhone=document.getElementsByClassName("userphone")[0].value;
						var reg =/^1\d{10}$/;
						if(reg.test(userPhone)){
							ajax({
								url:"http://www.antmall.cc/public/wx/collect/data/checkSign.html?activeId=10135",
						
								success:function(data){
									var data = JSON.parse(data);
									if(!data.code){
										var req = {"activeId":info.data.active.base.id,"userName":userName,"userPhone":userPhone,"giftId":gifts[i].id};
										$.post("http://www.antmall.cc/public/wx/collect/data/sign.html",req,function(res){
											var res = $.parseJSON(res);
											var mppId=res.data.mppId;
												window.location.href="participate.html";
										});
									}else {
										console.log("已参加活动")
									}
								}
							})	
						}else {
						console.log("请输入正确的手机号");
						}
					}
				}
			}
		}
		address.innerHTML=info.data.active.bizShop.address;

		

	}
})





function ajax(info){
	if(window.XMLHttpRequest){
		var xhr = new XMLHttpRequest();	
	}else{
		var xhr = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url = info.url;
	var type = info.type||"GET";
	var data = info.data||"";
	
	if(type=="GET"){
		xhr.open("GET",url,true);
		xhr.send();
	}else{
		xhr.open("POST",url,true);
		xhr.setRequestHeader("myHeader","myvalue");
		xhr.send(data);
	}
	
	xhr.onload = function(){
		if(info.success){
			info.success(xhr.responseText);
		}
	}
}
